﻿using DotNet.Highcharts;
using DotNet.Highcharts.Helpers;
using DotNet.Highcharts.Options;
using StockAnalyzerApp.Services.Impl;
using StockAnalyzerApp.ViewModels;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace StockAnalyzerApp.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            IndexViewModel indexViewModel = doGet();

            return View(indexViewModel);
        }

        [HttpPost]
        public ActionResult Index(String i_symbol1, String i_industry1, String i_sector1,
            String i_symbol2, String i_industry2, String i_sector2,
            String i_fromDate, String i_toDate, String seletedDataRangeType)
        {
            IndexViewModel indexViewModel = doGet();
            if (ModelState.IsValid && i_symbol1 != "" && i_symbol2 != "" && i_fromDate != "" && i_toDate != "" && seletedDataRangeType != "")
            {
                indexViewModel.i_symbol1 = i_symbol1;
                indexViewModel.i_industry1 = i_industry1;
                indexViewModel.i_sector1 = i_sector1;
                indexViewModel.i_symbol2 = i_symbol2;
                indexViewModel.i_industry2 = i_industry2;
                indexViewModel.i_sector2 = i_sector2;
                indexViewModel.i_fromDate = i_fromDate;
                indexViewModel.i_toDate = i_toDate;
                indexViewModel.seletedDataRangeType = seletedDataRangeType;

                GraphService graphService = new GraphService();
                Highcharts chart = graphService.updateGraph(seletedDataRangeType, i_symbol1, i_symbol2, i_fromDate, i_toDate);
                indexViewModel.highcharts = chart;

                System.Diagnostics.Debug.WriteLine("seletedDataRangeType " + seletedDataRangeType);
                System.Diagnostics.Debug.WriteLine("i_fromDate " + i_fromDate);
                System.Diagnostics.Debug.WriteLine("i_toDate " + i_toDate);
                System.Diagnostics.Debug.WriteLine("i_symbol1 " + i_symbol1);
                System.Diagnostics.Debug.WriteLine("i_symbol2 " + i_symbol2);
            }
            return View(indexViewModel);
        }
        public IndexViewModel doGet()
        {
            IndexViewModel indexViewModel = new IndexViewModel();

            ///////////////////////////////
            //Set values for Industry Name dropdown
            IndustryInfoService industryInfoService = new IndustryInfoService();
            List<IndustryInfoItem> industryInfoList = industryInfoService.getIndustryInfoData();
            indexViewModel.industryInfoList = industryInfoList;

            //Set values for Date Range Type radiobutton list
            Dictionary<string, string> rbl_dateRangeTypeList = new Dictionary<string, string>();
            rbl_dateRangeTypeList.Add("Weekly", "WeeklyData");
            rbl_dateRangeTypeList.Add("Monthly", "MonthlyData");
            rbl_dateRangeTypeList.Add("Quarterly", "QuarterlyData");
            indexViewModel.dateRangeTypeList = rbl_dateRangeTypeList;

            indexViewModel.seletedDataRangeType = "WeeklyData";

            return indexViewModel;
        }
        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
    }
}